package com.yanqu.road.server.cmd.variety;

import com.yanqu.road.pb.variety.VarietyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.match.CrossMatchMgr;
import com.yanqu.road.server.manager.match.MatchWeekRankModel;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/3/17 20:53
 */
@Cmd(code = CrossProtocol.C_VARIETY_GET_WEEK_RANK_REWARD, desc = "获取排行榜奖励")
public class GetVarietyWeekRankRewardCmd extends CrossCommand {
    private long groupId;
    private int weekId;
    private int type;
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        VarietyProto.GetWeekRankRewardCrossReqMsg msg = VarietyProto.GetWeekRankRewardCrossReqMsg.parseFrom(packet.getBytes());
        groupId = msg.getGroupId();
        weekId = msg.getWeekId();
        type = msg.getType();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        VarietyProto.GetWeekRankRewardCrossRespMsg.Builder respMsg = VarietyProto.GetWeekRankRewardCrossRespMsg.newBuilder();
        respMsg.setMyRank(-1);
        MatchWeekRankModel rankListModel = CrossMatchMgr.getRankListModel(groupId, weekId);
        if (rankListModel == null || rankListModel.getRankList().size() == 0) {
            respMsg.setMyRank(0);
        } else {
            int myRank = rankListModel.getMyRank(packet.getPlayerId(), serverId);
            respMsg.setMyRank(myRank);
        }
        respMsg.setType(type);
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(GameProtocol.S_VARIETY_GET_WEEK_RANK_REWARD_CROSS_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), pbMsg);
    }

    @Override
    public void sendData() {

    }
}
